# -*- coding: UTF-8 -*-

from commons import *

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


def send_mail(recivers, sub, content, filespath):
    try:
        user = "gnosis" + "<" + "gaojing1996@vip.qq.com" + ">"
        # 创建一个带附件的实例
        message = MIMEMultipart()
        message['Subject'] = sub
        message['From'] = user
        message['To'] = ";".join(recivers)

        # 邮件正文内容
        message.attach(MIMEText(content, 'plain', 'utf-8'))

        server = smtplib.SMTP_SSL("smtp.qq.com", 465)
        server.connect("smtp.qq.com", 465)  # 启用SSL发信, 端口一般是465
        server.login("gaojing1996@vip.qq.com", "onhklqsnrliqbbfg")
        server.sendmail(user, recivers, message.as_string())
        server.close()
        print("---Email_SEND_SUCCESSED--- 邮件发送成功 ---Email_SEND_SUCCESSED---")
    except Exception as e:
        print("---Email_Error--- 发送邮件出错！ ---Email_Error---")
        print(e)
